package com.duobaoyu.dby.supply.biz.client.resource.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.common.core.constant.SecurityConstants;
import com.duobaoyu.dby.common.core.constant.ServiceNameConstants;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.resource.admin.feign.RemoteResourceExpressInfoAdminService;
import com.duobaoyu.dby.resource.common.admin.dto.config.*;
import com.duobaoyu.dby.resource.remote.common.to.logistics.ExpressInfoTO;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceExpressInfoAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.*;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ExpressInfoVO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import com.duobaoyu.dby.supply.biz.util.RemoteResultCheckUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ResourceExpressInfoAdminClientImpl
 * @createTime 14:49:00 2023/10/08
 */
@Component
@RequiredArgsConstructor
public class ResourceExpressInfoAdminClientImpl implements ResourceExpressInfoAdminClient {

    private final ResourceConverter resourceConverter;
    private final RemoteResourceExpressInfoAdminService remoteResourceExpressInfoAdminService;


    @Override
    public Page<ExpressInfoVO> page(ExpressInfoQueryDTO expressInfoQuery) {
        ExpressQueryDTO dto = resourceConverter.toExpressQuery(expressInfoQuery);
        R<Page<ExpressInfoTO>> result = remoteResourceExpressInfoAdminService.page(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, expressInfoQuery);
        return resourceConverter.toExpressInfoPage(result.getData());
    }

    @Override
    public Boolean saveExpressInfo(ExpressInfoSaveDTO expressInfoSave) {
        ExpressSaveDTO dto = resourceConverter.toExpressSave(expressInfoSave);
        R<Boolean> result = remoteResourceExpressInfoAdminService.saveExpressInfo(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, expressInfoSave);
        return result.getData();
    }

    @Override
    public Boolean updateExpressInfo(ExpressInfoUpdateDTO expressInfoUpdate) {
        ExpressUpdateDTO dto = resourceConverter.toExpressUpdate(expressInfoUpdate);
        R<Boolean> result = remoteResourceExpressInfoAdminService.updateExpressInfo(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, expressInfoUpdate);
        return result.getData();
    }

    @Override
    public Boolean updateStatus(ExpressInfoStatusDTO expressInfoStatus) {
        ExpressStatusDTO dto = resourceConverter.toExpressStatus(expressInfoStatus);
        R<Boolean> result = remoteResourceExpressInfoAdminService.updateStatus(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, expressInfoStatus);
        return result.getData();
    }

    @Override
    public Boolean deleteExpressInfo(ExpressInfoDeleteDTO expressInfoDelete) {
        ExpressDeleteDTO dto = resourceConverter.toExpressDelete(expressInfoDelete);
        R<Boolean> result = remoteResourceExpressInfoAdminService.deleteExpressInfo(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, expressInfoDelete);
        return result.getData();
    }
}
